var ip = uni.getStorageSync("IP")
var port = uni.getStorageSync("Port")

const baseUrl = `http://${ip}:${port}/api/` //"http://" + ip + ":" + port;
console.log(baseUrl + '默认地址')
// request.js

const request = (url, method = 'GET', data = {}, header = {
	'content-type': 'application/json',
	'Access-Control-Allow-Origin': '*'
}) => {
	return new Promise((resolve, reject) => {
		//header["Authorization"] ="token-mjmjmmmjjj";
		uni.request({
			url: `http://${uni.getStorageSync("IP")}:${uni.getStorageSync("Port")}/api/${url}`,
			method: method,
			data: data,
			header: header,
			dataType: 'json',
			success: (res) => {
				if (res.data.code == 401) {
					uni.reLaunch({
						url: "/pages/login/login"
					})
				}
				resolve(res.data)
			},
			fail: (err) => {
				let result = {
					code: 500,
					msg: "获取数据失败"
				};
				reject(result)
			}
		})
	})
}


export default request